﻿Imports System.IO
Imports System.Threading
''' <summary>
''' 
''' </summary>
''' <remarks></remarks>
<Serializable()> Public Class StrPrintOut
    Private m_PrintOutResultAuto() As PrintResultAutoDist
    Private m_PrintOutResultDicrete() As PrintResultDiscrete
    Private m_PrintOutResultMax() As PrintResultMax

    Private m_PrintOutMaxConc As Double
    Private m_PrintOutMaxDistance As Double
    Private Const m_StaticDouble As Double = 1000

    Dim m_Presult1 As Boolean = False
    Dim m_Presult2 As Boolean = False
    Dim m_Presult3 As Boolean = False
    Private m_PrintOutResultComplex() As PrintResultComplex '复杂地形的距离及浓度的处理
    Private m_Presult4 As Boolean = False

    ''' <summary>
    ''' 自动距离
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property PrintOutResultAuto() As PrintResultAutoDist()
        Get
            Return m_PrintOutResultAuto
        End Get
        Set(ByVal value As PrintResultAutoDist())
            m_PrintOutResultAuto = value
        End Set
    End Property
    ''' <summary>
    ''' 离散距离
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property PrintOutResultDicrete() As PrintResultDiscrete()
        Get
            Return m_PrintOutResultDicrete
        End Get
        Set(ByVal value As PrintResultDiscrete())
            m_PrintOutResultDicrete = value
        End Set
    End Property
    ''' <summary>
    ''' 最大值
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property PrintOutResultMax() As PrintResultMax()
        Get
            Return m_PrintOutResultMax
        End Get
        Set(ByVal value As PrintResultMax())
            m_PrintOutResultMax = value
        End Set
    End Property
    ''' <summary>
    ''' 比较后的最大浓度
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property PrintOutMaxConc() As Double
        Get
            Return m_PrintOutMaxConc
        End Get
        Set(ByVal value As Double)
            m_PrintOutMaxConc = value
        End Set
    End Property
    ''' <summary>
    ''' 最大浓度跟随的距离
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property PrintOutMaxDistance() As Double
        Get
            Return m_PrintOutMaxDistance
        End Get
        Set(ByVal value As Double)
            m_PrintOutMaxDistance = value
        End Set
    End Property

    
    Property Presult1() As Boolean
        Get
            Return m_Presult1
        End Get
        Set(ByVal value As Boolean)
            m_Presult1 = value
        End Set
    End Property
    Property Presult2() As Boolean
        Get
            Return m_Presult2
        End Get
        Set(ByVal value As Boolean)
            m_Presult2 = value
        End Set
    End Property
    Property Presult3() As Boolean
        Get
            Return m_Presult3
        End Get
        Set(ByVal value As Boolean)
            m_Presult3 = value
        End Set
    End Property
    ''' <summary>
    ''' 复杂地形的距离及浓度的处理
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property PrintOutResultComplex() As PrintResultComplex()
        Get
            Return m_PrintOutResultComplex
        End Get
        Set(ByVal value As PrintResultComplex())
            m_PrintOutResultComplex = value
        End Set
    End Property
    Property Presult4() As Boolean
        Get
            Return m_Presult4
        End Get
        Set(ByVal value As Boolean)
            m_Presult4 = value
        End Set
    End Property
    Dim filename As String = My.Application.Info.DirectoryPath & "\" & "Models\" & "SCREEN.OUT"

    ''' <summary>
    ''' 自动距离
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub AutoMatedShowResult()
        Dim str As String = " *** SCREEN AUTOMATED DISTANCES ***"
        Dim j As Integer = 0
        Dim Count As Integer = 0
        Dim P8 As Boolean = False
        Dim Pr As Boolean = False
        FileOpen(1, filename, OpenMode.Input)
        If My.Computer.FileSystem.FileExists(My.Application.Info.DirectoryPath & "\" & "Models\" & "SCREEN.OUT") = True Then
            Do Until EOF(1)
                Dim strline As String = LineInput(1)
                If strline = str Then
                    P8 = True
                    Continue Do
                End If
                If P8 = True Then
                    Count = Count + 1
                End If
                If Count = 8 Then
                    Pr = True
                End If
                If Pr = True Then
                    If strline.Length > 2 Then
                        ReDim Preserve PrintOutResultAuto(j)
                        PrintOutResultAuto(j) = New PrintResultAutoDist
                        PrintOutResultAuto(j).AutoConc = StringHandle.GetString(strline, 2)
                        PrintOutResultAuto(j).AutoConc = Math.Round(PrintOutResultAuto(j).AutoConc / m_StaticDouble, 7)

                        PrintOutResultAuto(j).AutoDist = StringHandle.GetString(strline, 1)
                        j = j + 1
                        Presult1 = True
                    Else
                        Pr = False
                        P8 = False
                        Count = 0
                    End If
                End If
            Loop
            FileClose(1)
        End If
    End Sub
    ''' <summary>
    ''' 离散距离
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub DiscreteShowResult()
        Dim str As String = " *** SCREEN DISCRETE DISTANCES ***"
        Dim j As Integer = 0
        Dim Count As Integer = 0
        Dim P8 As Boolean = False
        Dim Pr As Boolean = False
        FileOpen(1, filename, OpenMode.Input)
        If My.Computer.FileSystem.FileExists(My.Application.Info.DirectoryPath & "\" & "Models\" & "SCREEN.OUT") = True Then

            Do Until EOF(1)
                Dim strline As String = LineInput(1)
                If strline = str Then
                    P8 = True

                    Continue Do
                End If
                If P8 = True Then
                    Count = Count + 1
                End If
                If Count = 8 Then
                    Pr = True
                End If
                If Pr = True Then
                    If strline.Length > 2 Then
                        ReDim Preserve PrintOutResultDicrete(j)
                        PrintOutResultDicrete(j) = New PrintResultDiscrete
                        PrintOutResultDicrete(j).DiscreteConc = StringHandle.GetString(strline, 2)
                        PrintOutResultDicrete(j).DiscreteConc = Math.Round(PrintOutResultDicrete(j).DiscreteConc / m_StaticDouble, 7)

                        PrintOutResultDicrete(j).Discretedist = StringHandle.GetString(strline, 1)
                        j = j + 1
                        Presult2 = True
                    Else
                        Pr = False
                        P8 = False
                        Count = 0
                    End If
                End If
            Loop
            FileClose(1)
        End If
    End Sub
    ''' <summary>
    ''' 处理最值
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub MaxValuesShowResult()
        Dim str As String = "      *** SUMMARY OF SCREEN MODEL RESULTS ***"
        Dim strResult As String = " ***************************************************"
        Dim j As Integer = 0
        Dim Count As Integer = 0
        Dim P8 As Boolean = False
        Dim Pr As Boolean = False
        'FileOpen(1, LoadDlg.FileName, OpenMode.Input)
        'If LoadDlg.FileName <> "" Then
        Dim StrCount As Integer = 0
        Dim StrNumber As Integer = 0
        PrintOutMaxConc = 0
        PrintOutMaxDistance = 0
        FileOpen(1, filename, OpenMode.Input)
        If My.Computer.FileSystem.FileExists(My.Application.Info.DirectoryPath & "\" & "Models\" & "SCREEN.OUT") = True Then
            Do Until EOF(1)
                Dim strline As String = LineInput(1)
                Dim NameStr As String = ""
                If strline = str Then
                    P8 = True
                    Continue Do
                End If
                If P8 = True Then
                    Count = Count + 1
                End If
                If Count = 6 Then
                    Pr = True
                    StrCount = StringHandle.GetStringNumber(strline)
                End If
                If Pr = True Then
                    If strline.Length > 3 Then
                        If strline <> strResult Then
                            ReDim Preserve PrintOutResultMax(j)
                            PrintOutResultMax(j) = New PrintResultMax
                            For i As Integer = 1 To StrCount
                                If StringHandle.GetString(strline, i).Substring(0, i) >= "A" And StringHandle.GetString(strline, 1).Substring(0, 1) <= "Z" Then
                                    'PrintOutResultMax(j).StrName = PrintOutResultMax(j).StrName & StringHandle.GetString(strline, i)
                                    NameStr = NameStr & StringHandle.GetString(strline, i) & " "
                                Else
                                    StrNumber = i
                                    Exit For
                                End If
                            Next
                            PrintOutResultMax(j).StrName = NameStr.Trim
                            PrintOutResultMax(j).MaxConc = StringHandle.GetString(strline, StrNumber)
                            PrintOutResultMax(j).MaxConc = Math.Round(PrintOutResultMax(j).MaxConc / m_StaticDouble, 7)

                            PrintOutResultMax(j).MaxDist = StringHandle.GetString(strline, StrNumber + 1)
                            PrintOutResultMax(j).MaxHight = StringHandle.GetString(strline, StrNumber + 2)

                            If PrintOutMaxConc < PrintOutResultMax(j).MaxConc Then
                                PrintOutMaxConc = PrintOutResultMax(j).MaxConc
                                PrintOutMaxDistance = PrintOutResultMax(j).MaxDist
                            End If
                            If EOF(1) = False Then
                                Dim sss = LineInput(1)
                            End If
                        Else
                            Pr = False
                            P8 = False
                            Count = 0
                        End If
                        j = j + 1
                        Presult3 = True
                    Else
                        Pr = False
                        P8 = False
                        Count = 0
                    End If
                End If
            Loop
            FileClose(1)
        End If
    End Sub

    ''' <summary>
    ''' 复杂地形距离及浓度的处理结果
    ''' </summary>
    ''' <remarks></remarks>
    Public Sub ComplexShowResult()
        Dim str As String = "                          *VALLEY 24-HR CALCS*   **SIMPLE TERRAIN 24-HR CALCS**"
        Dim j As Integer = 0
        Dim Count As Integer = 0
        Dim P8 As Boolean = False
        Dim Pr As Boolean = False
        FileOpen(1, filename, OpenMode.Input)
        If My.Computer.FileSystem.FileExists(My.Application.Info.DirectoryPath & "\" & "Models\" & "SCREEN.OUT") = True Then
            Do Until EOF(1)
                Dim strline As String = LineInput(1)
                If strline = str Then
                    P8 = True
                    Continue Do
                End If
                If P8 = True Then
                    Count = Count + 1
                End If
                If Count = 5 Then
                    Pr = True
                End If
                If Pr = True Then
                    If strline.Length > 2 Then
                        If StringHandle.GetString(strline, 1).Length <> 8 Then
                            ReDim Preserve PrintOutResultComplex(j)
                            PrintOutResultComplex(j) = New PrintResultComplex
                            PrintOutResultComplex(j).ComplexConc = StringHandle.GetString(strline, 3)
                            PrintOutResultComplex(j).ComplexConc = Math.Round(PrintOutResultComplex(j).ComplexConc / m_StaticDouble, 7)

                            PrintOutResultComplex(j).ComplexDist = StringHandle.GetString(strline, 2)
                            j = j + 1
                            Presult4 = True
                        Else
                            Pr = False
                            P8 = False
                            Count = 0
                        End If
                    Else
                        Pr = False
                        P8 = False
                        Count = 0
                    End If
                End If
            Loop
            FileClose(1)
        End If
    End Sub
End Class
